<template>
    <el-form ref="form" :model="curData" label-width="100px" :inline="true" :rules="rules" status-icon>
        <el-form-item label="编码:" prop="code">
            <el-input v-model.trim="curData.code" placeholder="请输入编码" size="small"></el-input>
        </el-form-item>
        <el-form-item label="名称:" prop="name">
            <el-input v-model.trim="curData.name" placeholder="请输入名称" size="small"></el-input>
        </el-form-item>
        <el-form-item label="用户类型:" prop="type">
            <el-select v-model="curData.type" placeholder="请选择用户类型" size="small" clearable :disabled="curData.id != null">
                <el-option v-for="(item,index) in userTypes" :label="item.label" :value="+item.value"
                           :key="index"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="状态:" prop="enabled" size="small"  class = "formInline">
            <el-switch v-model="curData.enabled" active-color="#13ce66" :active-value="1"
                       :inactive-value="0"></el-switch>
        </el-form-item>
        <el-form-item class="formBtn">
            <el-button type="info" @click="handleCancel" size="medium">取消</el-button>
            <el-button type="primary" @click="handleSubmit" size="medium">确定</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    import edtiMixin from '@/mixins/edit.mixin'
    import rules from './rules';
    import {mapState, mapActions} from 'vuex'
    export default {
        mixins: [edtiMixin],
        data() {
            return {
                rules: rules(this),
                addApi: this.$api.system.role.add,
                editApi: this.$api.system.role.edit
            };
        },
        computed: {
            ...mapState('dic', ['userTypes'])
        },
        methods: {
            ...mapActions('dic',['doUserTypesOfBasic']),
        },
        mounted() {
            this.doUserTypesOfBasic().then(result => {
                if(!this.curData.id) {
                    this.curData.type = this.userTypes && parseInt(this.userTypes[0].value) || 0;
                }
            });
        }
    };
</script>
<style scoped lang="less">
    @import "../../../assets/css/common.less";
</style>
